package com.mstore.dao;

import java.util.List;

import com.mstore.pojo.Goods;

public class GoodsDao extends SuperDao {
	
	/**
	 * 保存
	 * @param good
	 * @return
	 */
	public boolean save(Goods good){
		this.getHibernateTemplate().save(good);
		return true;
	}
	
	public Goods FindById(long id){
		return (Goods)this.getHibernateTemplate().get(Goods.class,id);
	}
	
	public boolean Delete(Goods good){
		 this.getHibernateTemplate().delete(good);
		return true;
	}
	/**
	 * 查询所有数据并分页
	 * @param goos
	 * @param index
	 * @return
	 */
	public List<Object> getList(Goods good,int index){
		StringBuilder sb=new StringBuilder();
		sb.append("From Goods");
		return super.findPage(index, sb.toString());
	}
	
	public int  getCount() {
		String hql = "Select Count(*) From Goods";
		 //int count=this.getHibernateTemplate().find(hql).size(); return count;
		List<Object> list = find(hql);
		Long s=(Long)list.get(0);
		return s.intValue();
	}
	
	/**
	 * 根据商品类别（顶层属性）
	 */
	public List<Object> getGoodsByGoodsType(String goodsType) {
		String sql = "from Goods where goodsType = ?";
		return getObject(sql, new Object[] { goodsType });
	}
}
